package com.ld.security.server.blog.modules.cms.vo;

import com.ld.security.common.core.base.SuperVo;
import com.ld.security.common.core.util.JsonUtil;
import com.ld.security.common.mybatis.anno.QueryKey;
import com.ld.security.common.mybatis.anno.SqlKey;
import com.ld.security.common.mybatis.base.vo.ProxyVo;
import com.ld.security.common.mybatis.constant.SqlCondition;
import com.ld.security.server.blog.modules.cms.entity.CmsCollectEntity;
import com.ld.security.server.blog.modules.cms.entity.CmsContentEntity;
import com.ld.security.server.user.modules.rec.constant.RecCardConstant;
import com.ld.security.server.user.modules.rec.entity.RecCardEntity;
import lombok.Data;

import java.util.List;
import java.util.Map;

@Data
public class AdminVo implements SuperVo,ProxyVo {

    private String upsUserId;

    @QueryKey
    @SqlKey(name = "upsUserId",valueField = "upsUserId")
    private List<RecCardEntity> cardList;


    @QueryKey
    @SqlKey(name = "id",value = SqlCondition.in,valueField = "cardList.contentId")
    private List<CmsCollectEntity> cols = null;

    @QueryKey
    @SqlKey(name = "id",value = SqlCondition.in,valueField = "cardList.contentId")
    private List<CmsContentEntity> cons = null;

    private List<CmsCon> contents;

    private List<CmsColl> collects;



    @Override
    public void queryAfter() {
        List<CmsColl> cols =  JsonUtil.clone(this.cols,List.class,CmsColl.class);
        List<CmsCon> cons =  JsonUtil.clone(this.cons,List.class,CmsCon.class);

        for (RecCardEntity card : cardList) {
            for (CmsColl col : cols) {
               if(col.getId().equals(card.getContentId())){
                   col.setRecId(card.getId());
                   col.setWt(card.getWt());
               }

            }

            for (CmsCon col : cons) {
                if(col.getId().equals(card.getContentId())){
                    col.setRecId(card.getId());
                    col.setWt(card.getWt());
                }

            }


        }

        cols.sort((x,y) -> {
            return x.getWt() - y.getWt();
        });
        cons.sort((x,y) -> {
            return x.getWt() - y.getWt();
        });



        this.collects = cols;

        this.contents = cons;

        this.cardList = null;
        this.cols = null;
        this.cons = null;
    }

    @Data
    public static class CmsCon extends  CmsContentEntity{
        private Integer wt;
        private String recId;
    }

    @Data
    public static class CmsColl extends  CmsCollectEntity{
        private Integer wt;
        private String recId;
    }
}
